package logic

import (
	"context"
	"gitee.com/Cauchy_AQ/vxopen/model/redis"
	"time"

	"gitee.com/Cauchy_AQ/vxopen/rpc/wechat/internal/svc"
	"gitee.com/Cauchy_AQ/vxopen/rpc/wechat/wechat"

	"github.com/zeromicro/go-zero/core/logx"
)

type ScanQrcodeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewScanQrcodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScanQrcodeLogic {
	return &ScanQrcodeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ScanQrcodeLogic) ScanQrcode(in *wechat.ScanQrcodeReq) (*wechat.ScanQrcodeResp, error) {
	// 扫码事件成功后，绑定 ticket 和 openid，用于前端的轮询查询登录状态
	l.svcCtx.RDB.Set(context.Background(), redis.CacheQrcodeTicketPrefix+in.Ticket, in.Openid, ExpireQRCodeDefault*time.Second)

	return &wechat.ScanQrcodeResp{}, nil
}
